import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { Location } from '@angular/common';
import { User } from '../user';
import { ActivatedRoute } from '@angular/router';
import { TestService } from '../test.service';

@Component({
  selector: 'app-test-get-detail',
  templateUrl: './test-get-detail.component.html',
  styleUrls: ['./test-get-detail.component.css']
})
export class TestGetDetailComponent implements OnInit {
  user: User;
  @Output() whenBack = new EventEmitter<object>();
  constructor(private location: Location,
    private route: ActivatedRoute,
    private userService: TestService) { }

  ngOnInit() {
    this.getUser();
  }
  getUser(): void {
    const id = +this.route.snapshot.paramMap.get('id');
    this.userService.getUser(id).subscribe(user => this.user = user);
  }
  back(): void {
    this.whenBack.emit(this);
    this.location.back();
  }
}
